﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using JKF.Substructure;
using JKF.BusinessLayer.BLL;
using JKF.Entities.Model;

namespace JKF.Web.Sys.User
{
    public partial class User_Add : PageBase
    {
        /// <summary>
        /// 取得角色下拉Select
        /// </summary>
        protected string SysRole_Select
        {
            get { return new bllSYS_ROLE().GetSysRoleArea(2); }
        }
        /// <summary>
        /// 模块名称
        /// </summary>
        private const string module_name_en = "sys_user";

        protected void Page_Load(object sender, EventArgs e)
        {
            //CheckPermission();
            MODULE_NAME_EN = "SYS_USER";
            if (!IsPostBack)
            {
                // 判断当前角色是否为分店管理员
                SYS_ROLEinfo roleInfo = new bllSYS_ROLE().GetModel(bllSYS_USER.CurrentUser.ROLE_KEY);
                if (SysConfig.LocalShop.Contains(roleInfo.ROLE_NAME))
                {
                    //调用前台js方法
                    SHOPinfo shopInfo = new bllSHOP().GetModel(bllSYS_USER.CurrentUser.SHOP_CODE);
                    ClientScript.RegisterStartupScript(this.GetType(), "do_LocalFun", "SetLocalUserForm('"+shopInfo.SHOP_NAME+"','"+shopInfo.SHOP_CODE+"');", true);
                }
                // 判断是从添加店面过来的不，如果是的话就填充好
                if (!string.IsNullOrEmpty(base.P("shopCode")))
                {
                    try
                    { 
                        SHOPinfo shop = new bllSHOP().GetModel(base.Q("shopCode"));
                        ClientScript.RegisterStartupScript(this.GetType(), "do_LocalFun", "SetLocalUserForm('" + shop.SHOP_NAME + "','" + shop.SHOP_CODE + "');", true);
                    }
                    catch (Exception ex)
                    {

                        ClientScript.RegisterStartupScript(this.GetType(), "tishi", "alert('"+ex.Message+"')", true);
                    }
                    
                }
            }
        }
        /// <summary>
        /// 检查操作权限
        /// </summary>
        private void CheckPermission()
        {
            bllPermission permission = new bllPermission();
            permission.GetUserPermission(module_name_en, bllSYS_USER.CurrentUser.ROLE_KEY, ref base.Preview, ref base.Add, ref base.Edit, ref base.Delete);
            if (!base.Add && !base.Edit)
            {
                //关闭当前页面
                base.JavaScriptCloseWindow();
                return;
            }
        }
    }
}